package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.RDTeam.domain.MemberInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ProductCenterList;
import com.ruoyi.system.service.IProductCenterListService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 研发中心展示Controller
 *
 * @author ruoyi
 * @date 2025-02-01
 */
@RestController
@RequestMapping("/system/list")
public class ProductCenterListController extends BaseController
{
    @Autowired
    private IProductCenterListService productCenterListService;

    /**
     * 查询研发中心展示列表
     */
    @PreAuthorize("@ss.hasPermi('system:list:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductCenterList productCenterList)
    {
        startPage();
        List<ProductCenterList> list = productCenterListService.selectProductCenterListList(productCenterList);
        return getDataTable(list);
    }

    /**
     * 导出研发中心展示列表
     */
    @PreAuthorize("@ss.hasPermi('system:list:export')")
    @Log(title = "研发中心展示", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductCenterList productCenterList)
    {
        List<ProductCenterList> list = productCenterListService.selectProductCenterListList(productCenterList);
        ExcelUtil<ProductCenterList> util = new ExcelUtil<ProductCenterList>(ProductCenterList.class);
        util.exportExcel(response, list, "研发中心展示数据");
    }

    /**
     * 获取研发中心展示详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:list:query')")
    @GetMapping(value = "/{productId}")
    public AjaxResult getInfo(@PathVariable("productId") String productId)
    {
        return success(productCenterListService.selectProductCenterListByProductId(productId));
    }

    /**
     * 新增研发中心展示
     */
    @PreAuthorize("@ss.hasPermi('system:list:add')")
    @Log(title = "研发中心展示", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestParam("productId") String productId,
                          @RequestParam("productName") String productName,
                          @RequestParam("productType") String productType,
                          @RequestParam("pictureUrl") String pictureUrl,
                          @RequestParam("videoUrl") String videoUrl,
                          @RequestParam("productDetails") String productDetails,
                          @RequestParam("top") String top,
                          @RequestParam("productTime") String productTime,
                          @RequestParam("productBg") String productBg,
                          @RequestParam("giteeUrl") String giteeUrl,
                          @RequestParam("avatarFile") MultipartFile avatarFile,
                          @RequestParam("videoFile") MultipartFile videoFile)
    {
        ProductCenterList productCenterList = new ProductCenterList();
        productCenterList.setProductId(UUID.randomUUID().toString());
        productCenterList.setProductName(productName);
        productCenterList.setProductType(Long.valueOf(productType));
        productCenterList.setPictureUrl(pictureUrl);
        productCenterList.setVideoUrl(videoUrl);
        productCenterList.setProductDetails(productDetails);
        productCenterList.setTop(Long.valueOf(top));
        productCenterList.setProductTime(productTime);
        productCenterList.setProductBg(productBg);
        productCenterList.setGiteeUrl(giteeUrl);
        // 将文件设置到 memberInfo 对象中
        productCenterList.setAvatarFile(avatarFile);
        productCenterList.setVideoFile(videoFile);
        return toAjax(productCenterListService.insertProductCenterList(productCenterList));
    }

    /**
     * 修改研发中心展示
     */
    @PreAuthorize("@ss.hasPermi('system:list:edit')")
    @Log(title = "研发中心展示", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestParam("productId") String productId,
                           @RequestParam(value = "productName", required = false) String productName,
                           @RequestParam(value = "productType", required = false) String productType,
                           @RequestParam(value = "pictureUrl", required = false) String pictureUrl,
                           @RequestParam(value = "videoUrl", required = false) String videoUrl,
                           @RequestParam(value = "productDetails", required = false) String productDetails,
                           @RequestParam(value = "top", required = false) String top,
                           @RequestParam(value = "productTime", required = false) String productTime,
                           @RequestParam(value = "productBg", required = false) String productBg,
                           @RequestParam(value = "giteeUrl", required = false) String giteeUrl,
                           @RequestParam(value = "avatarFile", required = false) MultipartFile avatarFile,
                           @RequestParam(value = "videoFile", required = false) MultipartFile videoFile)
    {
        ProductCenterList productCenterList = new ProductCenterList();
        if (productId== null && productId.isEmpty()){
            productCenterList.setProductId(UUID.randomUUID().toString());
        }else {
            productCenterList.setProductId(productId);
        }
        productCenterList.setProductName(productName);
        productCenterList.setProductType(Long.valueOf(productType));
        productCenterList.setPictureUrl(pictureUrl);
        productCenterList.setVideoUrl(videoUrl);
        productCenterList.setProductDetails(productDetails);
        productCenterList.setTop(Long.valueOf(top));
        productCenterList.setProductTime(productTime);
        productCenterList.setProductBg(productBg);
        productCenterList.setGiteeUrl(giteeUrl);
        // 将文件设置到 memberInfo 对象中
        productCenterList.setAvatarFile(avatarFile);
        productCenterList.setVideoFile(videoFile);
        return toAjax(productCenterListService.updateProductCenterList(productCenterList));
    }

    /**
     * 删除研发中心展示
     */
    @PreAuthorize("@ss.hasPermi('system:list:remove')")
    @Log(title = "研发中心展示", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable String[] productIds)
    {
        return toAjax(productCenterListService.deleteProductCenterListByProductIds(productIds));
    }
}
